package com.scgl.process.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.process.domain.ScglRoute;
import com.scgl.process.service.IScglRouteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺路线Controller
 *
 * @author ruoyi
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/route")
public class ScglRouteController extends BaseController
{
    @Autowired
    private IScglRouteService scglRouteService;

    /**
     * 查询工艺路线列表
     */
    @RequiresPermissions("process:route:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglRoute scglRoute)
    {
        startPage();
        List<ScglRoute> list = scglRouteService.selectScglRouteList(scglRoute);
        return getDataTable(list);
    }

    /**
     * 导出工艺路线列表
     */
    @RequiresPermissions("process:route:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglRoute scglRoute)
    {
        List<ScglRoute> list = scglRouteService.selectScglRouteList(scglRoute);
        ExcelUtil<ScglRoute> util = new ExcelUtil<ScglRoute>(ScglRoute.class);
        util.exportExcel(response, list, "工艺路线数据");
    }

    /**
     * 获取工艺路线详细信息
     */
    @RequiresPermissions("process:route:query")
    @GetMapping(value = "/{desname}")
    public AjaxResult getInfo(@PathVariable("desname") String desname)
    {
        return success(scglRouteService.selectScglRouteByDesname(desname));
    }

    /**
     * 新增工艺路线
     */
    @RequiresPermissions("process:route:add")
    @Log(title = "工艺路线新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglRoute scglRoute)
    {
        return toAjax(scglRouteService.insertScglRoute(scglRoute));
    }

    /**
     * 修改工艺路线
     */
    @RequiresPermissions("process:route:edit")
    @Log(title = "工艺路线修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglRoute scglRoute)
    {
        return toAjax(scglRouteService.updateScglRoute(scglRoute));
    }

    /**
     * 删除工艺路线
     */
    @RequiresPermissions("process:route:remove")
    @Log(title = "工艺路线删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{desnames}")
    public AjaxResult remove(@PathVariable String[] desnames)
    {
        return toAjax(scglRouteService.deleteScglRouteByDesnames(desnames));
    }
}
